package org.come.Jpanel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.tool.image.ImageMixDeal;
import com.updateNew.MyIsif;
import org.come.entity.TeamRole;
import org.come.until.AnalysisString;
import org.come.until.MessagrFlagUntil;
import org.come.until.Util;

import com.tool.btn.TeamPanelBtn;
import com.tool.tcp.NewPart;
import com.tool.tcp.SpriteFactory;
import com.tool.tcpimg.UIUtils;



/**
 * 队伍个人信息面板
 * 
 * @author HGC<br>
 * @time 2019年12月30日 下午6:35:06<br>
 * @class 类名:TeamModelJpanel<br>
 */
public class TeamModelJpanel extends JPanel {

	/**
	 * 字段名:labName 名字<br>
	 * 字段名:labLvl 等级<br>
	 *
	 * @time 2019年12月30日 下午6:36:56<br>
	 */
	private JLabel labName, labLvl;
	/**
	 * 字段名:btnRace 种族<br>
	 *
	 * @time 2019年12月30日 下午6:38:45<br>
	 */
	private TeamPanelBtn btnRace;
	private TeamRole teamRole;
	private TeamJpanel teamJpanel;
	private NewPart part;
	private int index;
	private boolean isState;// 队伍内 还是队伍外

	public TeamModelJpanel(TeamJpanel jpanel, int path) {
		this.teamJpanel = jpanel;
		this.index = path;
		this.setPreferredSize(new Dimension(84, 174));
		this.setOpaque(false);
		this.setLayout(null);
		getLabName();
		getLabLvl();
		getBtnRace();
		this.addMouseListener(new MouseListener() {

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				if (teamRole != null) {
					teamJpanel.upXz(index);
				}
			}

			@Override
			public void mouseExited(MouseEvent e) {
				if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE12)) {
					MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
				}
				// TODO Auto-generated method stub
				if (teamRole != null) {
					teamJpanel.upSXz(-1);
				}
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE13)) {
					MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
				}
				else {
					MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
				}
				// TODO Auto-generated method stub
				if (teamRole != null) {
					teamJpanel.upSXz(index);
				}
			}

			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub

			}
		});
	}

	/**
	 * 展示数据
	 *
	 * @time 2019年12月31日 上午9:33:34<br>
	 * @param
	 */
	public void showRoleShow(TeamRole teamRole) {
		this.teamRole = teamRole;
		if (teamRole != null) {
			getLabName().setForeground(UIUtils.gradeForColor(teamRole.getGrade()));
			getLabLvl().setForeground(UIUtils.gradeForColor(teamRole.getGrade()));
			getLabName().setText(teamRole.getName());
			if(ImageMixDeal.huoquLogin(teamRole.getName()) == null){
				getLabLvl().setText(AnalysisString.lvl(teamRole.getGrade()));

			}else{

				getLabLvl().setText(AnalysisString.lvl(ImageMixDeal.huoquLogin(teamRole.getName()).getRoleShow().getGrade()));
			}
			getBtnRace().setText(Util.getRaceSting(teamRole.getSpeciesId()) + "族");
			getBtnRace().setVisible(true);
			isState = teamRole.getState() < 0;
			part=SpriteFactory.createPart(teamRole.getSpeciesId().toString(), 2, 1, null);
		} else {
			getLabName().setText(null);
			getLabLvl().setText(null);
			getBtnRace().setVisible(false);
			isState = false;
			part = null;
		}
	}

	/** 清空数据 */
	public void clearMessage() {
		teamRole = null;
		part = null;
		labName.setText(null);
		labLvl.setText(null);
		getBtnRace().setBtn(0);
	}

	private static ImageIcon icon;
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		if (isState) {
			if (icon == null) {
				icon = new ImageIcon("inkImg/old/background/S164.png");
			}
			g.drawImage(icon.getImage(), 0, 0, this);
		}
	}
	public JLabel getLabName() {
		if (labName == null) {
			labName = new JLabel("", SwingConstants.CENTER);
			labName.setBounds(1, 120, 76, 23);
			this.add(labName);
		}
		return labName;
	}

	public void setLabName(JLabel labName) {
		this.labName = labName;
	}

	public JLabel getLabLvl() {
		if (labLvl == null) {
			labLvl = new JLabel("", SwingConstants.CENTER);
			labLvl.setBounds(1, 144, 76, 23);
			this.add(labLvl);
		}
		return labLvl;
	}

	public void setLabLvl(JLabel labLvl) {
		this.labLvl = labLvl;
	}

	public TeamPanelBtn getBtnRace() {
		if (btnRace == null) {
			if("水墨UI".equals(MyIsif.getStyle())) {
				btnRace = new TeamPanelBtn("skin/8100226/newbutton/B30.png", 1, "",UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT);
				btnRace.setForeground(UIUtils.COLOR_BTNTEXT[1]);
			}else{
				btnRace = new TeamPanelBtn("inkImg/hongmu/1/B30h.png", 1, "",UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_FONT);
				btnRace.setForeground(UIUtils.COLOR_BTNPUTONG2[1]);
			}
			btnRace.setBounds(1, 100, 34, 17);
			this.add(btnRace);
		}
		return btnRace;
	}

	public void setBtnRace(TeamPanelBtn btnRace) {
		this.btnRace = btnRace;
	}

	public TeamRole getTeamRole() {
		return teamRole;
	}

	public void setTeamRole(TeamRole teamRole) {
		this.teamRole = teamRole;
	}

	public NewPart getPart() {
		return part;
	}

	public void setPart(NewPart part) {
		this.part = part;
	}

}
